//
//  UserInfomationAvatarTableViewCell.swift
//  LeTu
//
//  Created by gy on 2023/12/11.
//

import UIKit

class UserInfomationAvatarTableViewCell: BaseTableViewCell {

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        configUI()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        DispatchQueue.main.async {
            self.imgView.layerCornerRadius(self.imgView.height/2)
        }
    }
    
    func setItem(_ item: ListSectionItem) {
        
        titleLabel.text = item.title
        if let titleColor = item.titleColor {
            titleLabel.textColor = titleColor
        }
        if let titleFont = item.titleFont {
            titleLabel.font = titleFont
        }
        
        if let img = item.img, img.contains("http") {
            imgView.sd_setImage(with: URL.encodedURL(string: img))
        } else {
            imgView.image = UIImage()
        }
        
        arrowImgView.isHidden = !item.isShowArrow
        imgView.snp.updateConstraints { make in
            make.right.equalToSuperview().offset(-12-(item.isShowArrow ? 5:0))
        }
        
        lineView.isHidden = !item.isShowLineView
    }
    
    // MARK: - configUI
    func configUI() {
        
        contentView.addSubview(backView)
        backView.addSubview(titleLabel)
        backView.addSubview(arrowImgView)
        backView.addSubview(imgView)
        backView.addSubview(lineView)
        
        backView.snp.makeConstraints { make in
            make.left.equalTo(25)
            make.right.equalTo(-25)
            make.top.bottom.equalToSuperview()
        }
        titleLabel.snp.makeConstraints { make in
            make.left.centerY.equalToSuperview()
        }
        arrowImgView.snp.makeConstraints { make in
            make.right.centerY.equalToSuperview()
            make.width.equalTo(5)
            make.height.equalTo(10)
        }
        imgView.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-12-5)
            make.width.height.equalTo(34)
            make.centerY.equalToSuperview()
        }
        lineView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(CGFloat.app_lineHieght)
        }
        
    }
    private lazy var backView: UIView = {
        let backView = UIView()
        return backView
    }()
    private lazy var titleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.font = kSetPingFangRegular(14)
        return titleLabel
    }()
    private lazy var arrowImgView: UIImageView = {
        let arrowImgView = UIImageView()
        arrowImgView.image = UIImage(named: "cell_arrow_black")
        arrowImgView.contentMode = .scaleAspectFit
        return arrowImgView
    }()
    private lazy var imgView: UIImageView = {
        let imgView = UIImageView()
        imgView.contentMode = .scaleAspectFill
        return imgView
    }()
    private lazy var lineView: UIView = {
        let lineView = UIView()
        lineView.backgroundColor = .app_lineColor
        return lineView
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
